package InputOutputStreamDemo;

import java.io.*;

public class FileInputStreamDemo {
    public static void main(String[] args) throws IOException {
        InputStream is = new FileInputStream(new File("d:\\Demo-Java\\java-demo-hbnu\\src\\aa.txt"));

//        int b ;
//        while ((b= is.read()) !=-1) {
//            System.out.print((char) b);
//        }
//        is.close();

//        byte[] buffer = new byte[3];
//        int len ;//判断读取了多少字节
//        while ((len = is.read(buffer))!=-1) {
//            String rs = new String(buffer, 0, len);
//            System.out.print(rs);
//        }
//        is.close();

        File f = new File("d:\\Demo-Java\\java-demo-hbnu\\src\\aa.txt");
        long size = f.length();
        byte[] buffer = new byte[(int) size];
        int len = is.read(buffer);
        System.out.println(new String(buffer, 0, len));
        System.out.println(size);
        System.out.println(len);

//        //jdk 9 以上才能使用
//        byte[] buffer = is.readAllBytes();
//        System.out.println(new String(buffer));

    }
}
